var Login={};
Login.contextpath="";
Login.initPage= function(contextpath){
	Login.contextpath =contextpath;
	layui.use(['form', 'layedit', 'laydate'], function(){
		var layer = layui.layer
		
	// 登录按钮
	$(document).on("click", "#login-button", function() {
		Login.ajaxLogin();
	});
	
	});
}

Login.ajaxLogin =function(){
	var username =$("#username").val();
	var password =$("#password").val();
	var client =Login.getClient();
	debugger;
    $.ajax({
        type:"POST",
        url:"/web2019/home/doLogin.action",
        dataType:"json",
        data:{
        	"userName":username,"password":password,"client":client
        },
        beforeSend:function(){
			layer.load(1);
		},
		complete:function(){
			layer.close(layer.index);
		},
        success:function(data){
        	console.log(data);
        	if(data.code=="0000"){
        		if(client=="pc"){
        			window.location.href = Login.contextpath+"/pages/getIndex.action";
        		}else{
        			window.location.href = Login.contextpath+"/mobile/index.action";
        		}
        		
        	}else{
        		$("#errorMessage").html(data.message);
        	}
        },
        error:function(data){
            
        }
    });
}
Login.getClient =function(){
	if(/Android|webOS|iPhone|iPod|BlackBerry|iPad|SymbianOS/i.test(navigator.userAgent)) {
	    console.log("is mobile ")
	    return "mobile";
	 } else {
	    console.log("is pc ")
	    return "pc";
	}}